package com.carpedil.smvc.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.springframework.stereotype.Component;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/** @author Administrator */
@Entity
@Getter
@Setter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "users")
@Component
public class User implements Serializable {
  @Id
  @Column(name = "id")
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Integer id;

  @Column(name = "user_name")
  private String userName;

  @Column(name = "pass_word")
  private String passWord;

  @Column(name = "nick_name")
  private String nickName;

  @Column(name = "reg_time")
  @JsonFormat(pattern = "yyyy-MM-dd")
  private Date regTime;

  @JsonIgnore
  @OneToOne(
      cascade = {CascadeType.PERSIST},
      fetch = FetchType.EAGER)
  @JoinColumn(name = "fk_user_detail_id")
  private UserDetail userDetail;

  @Override
  public String toString() {
    return "User{"
        + "id="
        + id
        + ", userName='"
        + userName
        + '\''
        + ", passWord='"
        + passWord
        + '\''
        + ", nickName='"
        + nickName
        + '\''
        + ", regTime="
        + regTime
        + ", userDetail="
        + userDetail
        + '}';
  }
}
